/******************************************************************************
 *
 * MotionViewer
 * Copyright (C) 2007 Sangyoon Lee, Electronic Visualization Laboratory, 
 * University of Illinois at Chicago
 *
 * This software is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either Version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License along
 * with this software; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Questions or comments about MotionViewer should be directed to 
 * cavern@evl.uic.edu
 *
 *****************************************************************************/

#ifndef __VICONMOTIONDATASET_H__
#define __VICONMOTIONDATASET_H__
#include <ogreplatform.h>
#include "ViconClientCodes.h"

enum tagMOTION_TYPE 
{
	MT_RTENGINE				= 0,
	MT_VFILE				= 1,
	MT_C3D					= 2,
	MT_NONE					= 3
};
typedef tagMOTION_TYPE MOTION_TYPE;


class ViconSubject;

class ViconMotionDataSet
{
public:

	ViconMotionDataSet();
	virtual ~ViconMotionDataSet();

	virtual void	rewind() {}
	virtual void	update(float addedTime);
	virtual void	connectToSource(const char* source);
	virtual void	getMarkerPosition(int id, float* pos);
	virtual void	getBodyTranslation(int id, float* trans, bool global = true);
	virtual void	getBodyRotation(int id, float* rot, bool global = true);
	virtual void	getBodyQuaternion(int id, float* qt, bool global = true);

	virtual int		getNumMarkers();
	virtual int		getNumBodies();
	virtual std::string getMarkerName(int id);
	virtual std::string getBodyName(int id);
	virtual int		getBodyIndex(std::string bodyname);
	virtual int		getMarkerIndex(std::string markername);

	void			setSpeed(float speed);
	void			increaseSpeed();
	void			decreaseSpeed();
	
	float			getSpeed() { return m_fSpeed;}
	float			getFrameRate() { return m_fFrameRate;}
	unsigned int	getTotalFrames() { return m_iTotFrames;}
	unsigned int	getCurrentFrame() { return m_iCurrFrame;}

	MOTION_TYPE		getType();
	std::string		getDebugBodyInfo();
	std::string		getDebugMarkerInfo();
	void			setDebug(bool value);

	void			loadSubject(const char* subject, const char* filename);
	bool			exportBVH(const char* filename);

	std::string		getSubjectName();
	std::string		getSubjectFullPath();
	std::string		getSubjectFileName();

	std::string		getName() { return m_sName;}
	std::string		getSourceName() { return m_sSource;}

protected:
	
	virtual void	updateDebug();

	MOTION_TYPE		m_tType;
	std::string		m_sName;
	std::string		m_sSource;
	std::string		m_sDebugBodyInfo;
	std::string		m_sDebugMarkerInfo;
	bool			m_bDebug;
	
	float			m_fFrameRate;
	float			m_fSpeed;
	unsigned int	m_iTotFrames;
	unsigned int	m_iCurrFrame;

	std::vector< MarkerChannel >	m_vMarkerChannels;
	std::vector< BodyChannel >		m_vBodyChannels;

	ViconSubject*	m_pSubject;

};

inline MOTION_TYPE 
ViconMotionDataSet::getType() 
{
	return m_tType;
}

inline std::string 
ViconMotionDataSet::getDebugBodyInfo() 
{ 
	return m_sDebugBodyInfo;
}

inline std::string 
ViconMotionDataSet::getDebugMarkerInfo() 
{ 
	return m_sDebugMarkerInfo;
}

inline void 
ViconMotionDataSet::setDebug(bool value) 
{ 
	m_bDebug = value;
}

// useful conversion function
void vtxVicon2Ogre(float* v);
void qtVicon2Ogre(float* q);
void rotVicon2Ogre(float* r);

#endif